﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// This class represents a mathematical closed interval.
    /// </summary>
    [Serializable]
    public class ClosedInterval : Interval
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ClosedInterval"/> class.
        /// </summary>
        public ClosedInterval()
            : base()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ClosedInterval"/> class.
        /// </summary>
        /// <param name="start">The start value for the interval.</param>
        /// <param name="end">The end value for the interval.</param>
        public ClosedInterval(double start, double end)
            : base(start, end)
        {
        }

        /// <summary>
        /// Determines whether the specified value [is in interval].
        /// </summary>
        /// <param name="value">The value to check.</param>
        /// <returns>
        /// 	<c>true</c> if [the specified value] [is in interval]; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsInInterval(double value)
        {
            return ((base.Start <= value) && (base.End >= value));
        }

        /// <summary>
        /// Determines whether all array values [are in the interval].
        /// </summary>
        /// <param name="value">The value array.</param>
        /// <returns>
        /// 	<c>true</c> if all array values [are in the interval]; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsInInterval(double[] value)
        {
            if (value == (double[]) ((object) null))
            {
                throw new ArgumentNullException("value");
            }

            foreach (double d in value)
            {
                if (!this.IsInInterval(d))
                {
                    return false;
                }
            }

            return true;
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return "[" + this.Start + ", " + this.End + "]";
        }
    }
}